1 Önsöz

Bu çalışma Kaggle’dan alınan DiabetesDataAnalysis(*) adlı veri seti ile hazırlanmıştır.

(*) https://www.kaggle.com/datasets/aemyjutt/diabetesdataanslysis/data

2 Veri Tanımı

Verimizi import edelim.

diabetes <- read.csv("diabetes.csv")
View(diabetes)
nrow(diabetes)
## [1] 768
ncol(diabetes)
## [1] 9

Veri seti 9 değişken ve 768 gözlem içermektedir.

3 Veri Seti İncelemesi

str(diabetes)
## 'data.frame':    768 obs. of  9 variables:
##  $ Pregnancies             : int  6 1 8 1 0 5 3 10 2 8 ...
##  $ Glucose                 : int  148 85 183 89 137 116 78 115 197 125 ...
##  $ BloodPressure           : int  72 66 64 66 40 74 50 0 70 96 ...
##  $ SkinThickness           : int  35 29 0 23 35 0 32 0 45 0 ...
##  $ Insulin                 : int  0 0 0 94 168 0 88 0 543 0 ...
##  $ BMI                     : num  33.6 26.6 23.3 28.1 43.1 25.6 31 35.3 30.5 0 ...
##  $ DiabetesPedigreeFunction: num  0.627 0.351 0.672 0.167 2.288 ...
##  $ Age                     : int  50 31 32 21 33 30 26 29 53 54 ...
##  $ Outcome                 : int  1 0 1 0 1 0 1 0 1 1 ...

Pregnancies: Hamile kalma sayısı.

Glucose: Şeker seviyesi.

BloodPressure: Kan basıncı (mm/Hg).

SkinThickness: Cilt kalınlığı (mm).

Insulin: İnsülin değeri (2 saatlik serum insülini)

BMI: Vücut kitle indeksi (kg/(boy)^2)

DiabetesPedigreeFunction: Diyabet soyağacı işlevi (aile geçmişine dayalı olarak diyabet olasılığını puanlayan bir işlev).

Age: Yaş

Outcome: Sonuç (0: Diyabeti yok, 1: Diyabeti var.)

3.1 Eksik Değer Kontrolü

Eksik gözlemleri kontrol edelim.

colSums(is.na(diabetes))
##              Pregnancies                  Glucose            BloodPressure 
##                        0                        0                        0 
##            SkinThickness                  Insulin                      BMI 
##                        0                        0                        0 
## DiabetesPedigreeFunction                      Age                  Outcome 
##                        0                        0                        0

Veri setinde eksik gözlem yokmuş gibi görünüyor. Ancak bazı gözlemlerde “0” yer alıyor olabilir. Bu durumu inceleyelim.

Pregnancies Değişkeni

Doğum bilgisini içeren bu değişkende “0” yer alması anormal bir durum olarak düşünülmez. Bu sebeple 0’lar incelenmeyecektir.

Glucose Değişkeni

Şeker hastalarında Glucose değeri, normal bireylerden farklılık gösterebileceği için bu değişkende de “0”lar incelenmeyecektir.

BloodPressure Değişkeni

zeroBloodPressure <- diabetes$BloodPressure == 0

diabetes[zeroBloodPressure, ]
##     Pregnancies Glucose BloodPressure SkinThickness Insulin  BMI
## 8            10     115             0             0       0 35.3
## 16            7     100             0             0       0 30.0
## 50            7     105             0             0       0  0.0
## 61            2      84             0             0       0  0.0
## 79            0     131             0             0       0 43.2
## 82            2      74             0             0       0  0.0
## 173           2      87             0            23       0 28.9
## 194          11     135             0             0       0 52.3
## 223           7     119             0             0       0 25.2
## 262           3     141             0             0       0 30.0
## 267           0     138             0             0       0 36.3
## 270           2     146             0             0       0 27.5
## 301           0     167             0             0       0 32.3
## 333           1     180             0             0       0 43.3
## 337           0     117             0             0       0 33.8
## 348           3     116             0             0       0 23.5
## 358          13     129             0            30       0 39.9
## 427           0      94             0             0       0  0.0
## 431           2      99             0             0       0 22.2
## 436           0     141             0             0       0 42.4
## 454           2     119             0             0       0 19.6
## 469           8     120             0             0       0 30.0
## 485           0     145             0             0       0 44.2
## 495           3      80             0             0       0  0.0
## 523           6     114             0             0       0  0.0
## 534           6      91             0             0       0 29.8
## 536           4     132             0             0       0 32.9
## 590           0      73             0             0       0 21.1
## 602           6      96             0             0       0 23.7
## 605           4     183             0             0       0 28.4
## 620           0     119             0             0       0 32.4
## 644           4      90             0             0       0 28.0
## 698           0      99             0             0       0 25.0
## 704           2     129             0             0       0 38.5
## 707          10     115             0             0       0  0.0
##     DiabetesPedigreeFunction Age Outcome
## 8                      0.134  29       0
## 16                     0.484  32       1
## 50                     0.305  24       0
## 61                     0.304  21       0
## 79                     0.270  26       1
## 82                     0.102  22       0
## 173                    0.773  25       0
## 194                    0.578  40       1
## 223                    0.209  37       0
## 262                    0.761  27       1
## 267                    0.933  25       1
## 270                    0.240  28       1
## 301                    0.839  30       1
## 333                    0.282  41       1
## 337                    0.932  44       0
## 348                    0.187  23       0
## 358                    0.569  44       1
## 427                    0.256  25       0
## 431                    0.108  23       0
## 436                    0.205  29       1
## 454                    0.832  72       0
## 469                    0.183  38       1
## 485                    0.630  31       1
## 495                    0.174  22       0
## 523                    0.189  26       0
## 534                    0.501  31       0
## 536                    0.302  23       1
## 590                    0.342  25       0
## 602                    0.190  28       0
## 605                    0.212  36       1
## 620                    0.141  24       1
## 644                    0.610  31       0
## 698                    0.253  22       0
## 704                    0.304  41       0
## 707                    0.261  30       1

BloodPressure değerleri 0 yazan gözlemler tespit edilmiştir.

SkinThickness Değişkeni

zeroSkinThickness <- diabetes$SkinThickness == 0

diabetes[zeroSkinThickness, ]
##     Pregnancies Glucose BloodPressure SkinThickness Insulin  BMI
## 3             8     183            64             0       0 23.3
## 6             5     116            74             0       0 25.6
## 8            10     115             0             0       0 35.3
## 10            8     125            96             0       0  0.0
## 11            4     110            92             0       0 37.6
## 12           10     168            74             0       0 38.0
## 13           10     139            80             0       0 27.1
## 16            7     100             0             0       0 30.0
## 18            7     107            74             0       0 29.6
## 22            8      99            84             0       0 35.4
## 23            7     196            90             0       0 39.8
## 27            7     147            76             0       0 39.4
## 30            5     117            92             0       0 34.1
## 34            6      92            92             0       0 19.9
## 37           11     138            76             0       0 33.2
## 42            7     133            84             0       0 40.2
## 45            7     159            64             0       0 27.4
## 47            1     146            56             0       0 29.7
## 50            7     105             0             0       0  0.0
## 59            0     146            82             0       0 40.5
## 61            2      84             0             0       0  0.0
## 62            8     133            72             0       0 32.9
## 63            5      44            62             0       0 25.0
## 65            7     114            66             0       0 32.8
## 68            2     109            92             0       0 42.7
## 73           13     126            90             0       0 43.4
## 77            7      62            78             0       0 32.6
## 79            0     131             0             0       0 43.2
## 82            2      74             0             0       0  0.0
## 85            5     137           108             0       0 48.8
## 91            1      80            55             0       0 19.1
## 94            4     134            72             0       0 23.8
## 101           1     163            72             0       0 39.0
## 102           1     151            60             0       0 26.1
## 103           0     125            96             0       0 22.5
## 105           2      85            65             0       0 39.6
## 107           1      96           122             0       0 22.4
## 114           4      76            62             0       0 34.0
## 116           4     146            92             0       0 31.2
## 117           5     124            74             0       0 34.0
## 118           5      78            48             0       0 33.7
## 124           5     132            80             0       0 26.8
## 125           0     113            76             0       0 33.3
## 130           0     105            84             0       0 27.9
## 132           9     122            56             0       0 33.3
## 139           0     129            80             0       0 31.2
## 141           3     128            78             0       0 21.1
## 144          10     108            66             0       0 32.4
## 149           5     147            78             0       0 33.7
## 152           4     114            65             0       0 21.9
## 155           8     188            78             0       0 47.9
## 165           0     131            88             0       0 31.6
## 168           4     120            68             0       0 29.6
## 169           4     110            66             0       0 31.9
## 171           6     102            82             0       0 30.8
## 177           6      85            78             0       0 31.2
## 179           5     143            78             0       0 45.0
## 180           5     130            82             0       0 39.1
## 181           6      87            80             0       0 23.2
## 184           5      73            60             0       0 26.8
## 185           4     141            74             0       0 27.6
## 191           3     111            62             0       0 22.6
## 193           7     159            66             0       0 30.4
## 194          11     135             0             0       0 52.3
## 197           1     105            58             0       0 24.3
## 202           1     138            82             0       0 40.1
## 208           5     162           104             0       0 37.7
## 220           5     112            66             0       0 37.8
## 222           2     158            90             0       0 31.6
## 223           7     119             0             0       0 25.2
## 227           0     101            76             0       0 35.7
## 231           4     142            86             0       0 44.0
## 234           4     122            68             0       0 35.0
## 236           4     171            72             0       0 43.6
## 240           0     104            76             0       0 18.4
## 243           3     139            54             0       0 25.6
## 247          10     122            68             0       0 31.2
## 251           9     106            52             0       0 31.2
## 252           2     129            84             0       0 28.0
## 262           3     141             0             0       0 30.0
## 265           4     123            62             0       0 32.0
## 267           0     138             0             0       0 36.3
## 269           0     102            52             0       0 25.1
## 270           2     146             0             0       0 27.5
## 273           3     122            78             0       0 23.0
## 275          13     106            70             0       0 34.2
## 279           5     114            74             0       0 24.9
## 281           0     146            70             0       0 37.9
## 284           7     161            86             0       0 30.4
## 285           2     108            80             0       0 27.0
## 295           0     161            50             0       0 21.9
## 300           8     112            72             0       0 23.6
## 301           0     167             0             0       0 32.3
## 304           5     115            98             0       0 52.9
## 305           3     150            76             0       0 21.0
## 318           3     182            74             0       0 30.5
## 320           6     194            78             0       0 23.5
## 328          10     179            70             0       0 35.1
## 333           1     180             0             0       0 43.3
## 334          12     106            80             0       0 23.6
## 337           0     117             0             0       0 33.8
## 338           5     115            76             0       0 31.2
## 340           7     178            84             0       0 39.9
## 344           5     122            86             0       0 34.7
## 345           8      95            72             0       0 36.8
## 348           3     116             0             0       0 23.5
## 351           4      92            80             0       0 42.2
## 352           4     137            84             0       0 31.2
## 355           3      90            78             0       0 42.7
## 356           9     165            88             0       0 30.4
## 362           5     158            70             0       0 29.8
## 364           4     146            78             0       0 38.5
## 367           6     124            72             0       0 27.6
## 379           4     156            75             0       0 48.3
## 392           5     166            76             0       0 45.7
## 395           4     158            78             0       0 32.9
## 399           3      82            70             0       0 21.1
## 401           4      95            64             0       0 32.0
## 402           6     137            61             0       0 24.2
## 405           5     168            64             0       0 32.9
## 407           4     115            72             0       0 28.9
## 408           0     101            62             0       0 21.9
## 409           8     197            74             0       0 25.9
## 419           1      83            68             0       0 18.2
## 427           0      94             0             0       0  0.0
## 431           2      99             0             0       0 22.2
## 434           2     139            75             0       0 25.6
## 436           0     141             0             0       0 42.4
## 438           5     147            75             0       0 29.9
## 440           6     107            88             0       0 36.8
## 444           8     108            70             0       0 30.5
## 452           2     134            70             0       0 28.9
## 454           2     119             0             0       0 19.6
## 457           1     135            54             0       0 26.7
## 462           1      71            62             0       0 21.8
## 465          10     115            98             0       0 24.0
## 469           8     120             0             0       0 30.0
## 474           7     136            90             0       0 29.9
## 475           4     114            64             0       0 28.9
## 485           0     145             0             0       0 44.2
## 490           8     194            80             0       0 26.1
## 495           3      80             0             0       0  0.0
## 496           6     166            74             0       0 26.6
## 497           5     110            68             0       0 26.0
## 506          10      75            82             0       0 33.3
## 510           8     120            78             0       0 25.0
## 513           9      91            68             0       0 24.2
## 514           2      91            62             0       0 27.3
## 518           7     125            86             0       0 37.6
## 519          13      76            60             0       0 32.8
## 523           6     114             0             0       0  0.0
## 524           9     130            70             0       0 34.2
## 525           3     125            58             0       0 31.6
## 530           0     111            65             0       0 24.6
## 532           0     107            76             0       0 45.3
## 534           6      91             0             0       0 29.8
## 536           4     132             0             0       0 32.9
## 537           0     105            90             0       0 29.6
## 538           0      57            60             0       0 21.7
## 553           6     114            88             0       0 27.8
## 558           8     110            76             0       0 27.8
## 560          11      85            74             0       0 30.1
## 561           6     125            76             0       0 33.8
## 565           0      91            80             0       0 32.4
## 571           3      78            70             0       0 32.5
## 572           2     130            96             0       0 22.6
## 578           2     118            80             0       0 42.9
## 579          10     133            68             0       0 27.0
## 584           8     100            76             0       0 38.7
## 587           8     143            66             0       0 34.9
## 588           6     103            66             0       0 24.3
## 590           0      73             0             0       0 21.1
## 593           3     132            80             0       0 34.4
## 597           0      67            76             0       0 45.3
## 599           1     173            74             0       0 36.8
## 602           6      96             0             0       0 23.7
## 605           4     183             0             0       0 28.4
## 616           3     106            72             0       0 25.8
## 617           6     117            96             0       0 28.7
## 620           0     119             0             0       0 32.4
## 623           6     183            94             0       0 40.8
## 625           2     108            64             0       0 30.8
## 627           0     125            68             0       0 24.7
## 628           0     132            78             0       0 32.4
## 629           5     128            80             0       0 34.6
## 631           7     114            64             0       0 27.4
## 633           2     111            60             0       0 26.2
## 635          10      92            62             0       0 25.9
## 636          13     104            72             0       0 31.2
## 637           5     104            74             0       0 28.8
## 642           4     128            70             0       0 34.3
## 643           6     147            80             0       0 29.5
## 644           4      90             0             0       0 28.0
## 654           2     120            54             0       0 26.8
## 659          11     127           106             0       0 39.0
## 661          10     162            84             0       0 27.7
## 675           8      91            82             0       0 35.6
## 676           6     195            70             0       0 30.9
## 677           9     156            86             0       0 24.8
## 678           0      93            60             0       0 35.3
## 679           3     121            52             0       0 36.0
## 684           4     125            80             0       0 32.3
## 685           5     136            82             0       0  0.0
## 687           3     130            64             0       0 23.1
## 691           8     107            80             0       0 24.6
## 692          13     158           114             0       0 42.3
## 695           2      90            60             0       0 23.5
## 698           0      99             0             0       0 25.0
## 700           4     118            70             0       0 44.5
## 704           2     129             0             0       0 38.5
## 707          10     115             0             0       0  0.0
## 709           9     164            78             0       0 32.8
## 715           3     102            74             0       0 29.5
## 725           1     111            94             0       0 32.8
## 729           2     175            88             0       0 22.9
## 730           2      92            52             0       0 30.1
## 732           8     120            86             0       0 28.4
## 735           2     105            75             0       0 23.3
## 740           1     102            74             0       0 39.5
## 744           9     140            94             0       0 32.7
## 750           6     162            62             0       0 24.3
## 751           4     136            70             0       0 31.2
## 758           0     123            72             0       0 36.3
## 759           1     106            76             0       0 37.5
## 760           6     190            92             0       0 35.5
## 763           9      89            62             0       0 22.5
## 767           1     126            60             0       0 30.1
##     DiabetesPedigreeFunction Age Outcome
## 3                      0.672  32       1
## 6                      0.201  30       0
## 8                      0.134  29       0
## 10                     0.232  54       1
## 11                     0.191  30       0
## 12                     0.537  34       1
## 13                     1.441  57       0
## 16                     0.484  32       1
## 18                     0.254  31       1
## 22                     0.388  50       0
## 23                     0.451  41       1
## 27                     0.257  43       1
## 30                     0.337  38       0
## 34                     0.188  28       0
## 37                     0.420  35       0
## 42                     0.696  37       0
## 45                     0.294  40       0
## 47                     0.564  29       0
## 50                     0.305  24       0
## 59                     1.781  44       0
## 61                     0.304  21       0
## 62                     0.270  39       1
## 63                     0.587  36       0
## 65                     0.258  42       1
## 68                     0.845  54       0
## 73                     0.583  42       1
## 77                     0.391  41       0
## 79                     0.270  26       1
## 82                     0.102  22       0
## 85                     0.227  37       1
## 91                     0.258  21       0
## 94                     0.277  60       1
## 101                    1.222  33       1
## 102                    0.179  22       0
## 103                    0.262  21       0
## 105                    0.930  27       0
## 107                    0.207  27       0
## 114                    0.391  25       0
## 116                    0.539  61       1
## 117                    0.220  38       1
## 118                    0.654  25       0
## 124                    0.186  69       0
## 125                    0.278  23       1
## 130                    0.741  62       1
## 132                    1.114  33       1
## 139                    0.703  29       0
## 141                    0.268  55       0
## 144                    0.272  42       1
## 149                    0.218  65       0
## 152                    0.432  37       0
## 155                    0.137  43       1
## 165                    0.743  32       1
## 168                    0.709  34       0
## 169                    0.471  29       0
## 171                    0.180  36       1
## 177                    0.382  42       0
## 179                    0.190  47       0
## 180                    0.956  37       1
## 181                    0.084  32       0
## 184                    0.268  27       0
## 185                    0.244  40       0
## 191                    0.142  21       0
## 193                    0.383  36       1
## 194                    0.578  40       1
## 197                    0.187  21       0
## 202                    0.236  28       0
## 208                    0.151  52       1
## 220                    0.261  41       1
## 222                    0.805  66       1
## 223                    0.209  37       0
## 227                    0.198  26       0
## 231                    0.645  22       1
## 234                    0.394  29       0
## 236                    0.479  26       1
## 240                    0.582  27       0
## 243                    0.402  22       1
## 247                    0.258  41       0
## 251                    0.380  42       0
## 252                    0.284  27       0
## 262                    0.761  27       1
## 265                    0.226  35       1
## 267                    0.933  25       1
## 269                    0.078  21       0
## 270                    0.240  28       1
## 273                    0.254  40       0
## 275                    0.251  52       0
## 279                    0.744  57       0
## 281                    0.334  28       1
## 284                    0.165  47       1
## 285                    0.259  52       1
## 295                    0.254  65       0
## 300                    0.840  58       0
## 301                    0.839  30       1
## 304                    0.209  28       1
## 305                    0.207  37       0
## 318                    0.345  29       1
## 320                    0.129  59       1
## 328                    0.200  37       0
## 333                    0.282  41       1
## 334                    0.137  44       0
## 337                    0.932  44       0
## 338                    0.343  44       1
## 340                    0.331  41       1
## 344                    0.290  33       0
## 345                    0.485  57       0
## 348                    0.187  23       0
## 351                    0.237  29       0
## 352                    0.252  30       0
## 355                    0.559  21       0
## 356                    0.302  49       1
## 362                    0.207  63       0
## 364                    0.520  67       1
## 367                    0.368  29       1
## 379                    0.238  32       1
## 392                    0.340  27       1
## 395                    0.803  31       1
## 399                    0.389  25       0
## 401                    0.161  31       1
## 402                    0.151  55       0
## 405                    0.135  41       1
## 407                    0.376  46       1
## 408                    0.336  25       0
## 409                    1.191  39       1
## 419                    0.624  27       0
## 427                    0.256  25       0
## 431                    0.108  23       0
## 434                    0.167  29       0
## 436                    0.205  29       1
## 438                    0.434  28       0
## 440                    0.727  31       0
## 444                    0.955  33       1
## 452                    0.542  23       1
## 454                    0.832  72       0
## 457                    0.687  62       0
## 462                    0.416  26       0
## 465                    1.022  34       0
## 469                    0.183  38       1
## 474                    0.210  50       0
## 475                    0.126  24       0
## 485                    0.630  31       1
## 490                    0.551  67       0
## 495                    0.174  22       0
## 496                    0.304  66       0
## 497                    0.292  30       0
## 506                    0.263  38       0
## 510                    0.409  64       0
## 513                    0.200  58       0
## 514                    0.525  22       0
## 518                    0.304  51       0
## 519                    0.180  41       0
## 523                    0.189  26       0
## 524                    0.652  45       1
## 525                    0.151  24       0
## 530                    0.660  31       0
## 532                    0.686  24       0
## 534                    0.501  31       0
## 536                    0.302  23       1
## 537                    0.197  46       0
## 538                    0.735  67       0
## 553                    0.247  66       0
## 558                    0.237  58       0
## 560                    0.300  35       0
## 561                    0.121  54       1
## 565                    0.601  27       0
## 571                    0.270  39       0
## 572                    0.268  21       0
## 578                    0.693  21       1
## 579                    0.245  36       0
## 584                    0.190  42       0
## 587                    0.129  41       1
## 588                    0.249  29       0
## 590                    0.342  25       0
## 593                    0.402  44       1
## 597                    0.194  46       0
## 599                    0.088  38       1
## 602                    0.190  28       0
## 605                    0.212  36       1
## 616                    0.207  27       0
## 617                    0.157  30       0
## 620                    0.141  24       1
## 623                    1.461  45       0
## 625                    0.158  21       0
## 627                    0.206  21       0
## 628                    0.393  21       0
## 629                    0.144  45       0
## 631                    0.732  34       1
## 633                    0.343  23       0
## 635                    0.167  31       0
## 636                    0.465  38       1
## 637                    0.153  48       0
## 642                    0.303  24       0
## 643                    0.178  50       1
## 644                    0.610  31       0
## 654                    0.455  27       0
## 659                    0.190  51       0
## 661                    0.182  54       0
## 675                    0.587  68       0
## 676                    0.328  31       1
## 677                    0.230  53       1
## 678                    0.263  25       0
## 679                    0.127  25       1
## 684                    0.536  27       1
## 685                    0.640  69       0
## 687                    0.314  22       0
## 691                    0.856  34       0
## 692                    0.257  44       1
## 695                    0.191  25       0
## 698                    0.253  22       0
## 700                    0.904  26       0
## 704                    0.304  41       0
## 707                    0.261  30       1
## 709                    0.148  45       1
## 715                    0.121  32       0
## 725                    0.265  45       0
## 729                    0.326  22       0
## 730                    0.141  22       0
## 732                    0.259  22       1
## 735                    0.560  53       0
## 740                    0.293  42       1
## 744                    0.734  45       1
## 750                    0.178  50       1
## 751                    1.182  22       1
## 758                    0.258  52       1
## 759                    0.197  26       0
## 760                    0.278  66       1
## 763                    0.142  33       0
## 767                    0.349  47       1

SkinThickness değerleri 0 yazan gözlemler tespit edilmiştir.

Insulin Değişkeni

Şeker hastalarında Insulin değeri, normal bireylerden farklılık gösterebileceği için bu değişkende de “0”lar incelenmeyecektir.

BMI Değişkeni

zeroBMI <- diabetes$BMI == 0

diabetes[zeroBMI, ]
##     Pregnancies Glucose BloodPressure SkinThickness Insulin BMI
## 10            8     125            96             0       0   0
## 50            7     105             0             0       0   0
## 61            2      84             0             0       0   0
## 82            2      74             0             0       0   0
## 146           0     102            75            23       0   0
## 372           0     118            64            23      89   0
## 427           0      94             0             0       0   0
## 495           3      80             0             0       0   0
## 523           6     114             0             0       0   0
## 685           5     136            82             0       0   0
## 707          10     115             0             0       0   0
##     DiabetesPedigreeFunction Age Outcome
## 10                     0.232  54       1
## 50                     0.305  24       0
## 61                     0.304  21       0
## 82                     0.102  22       0
## 146                    0.572  21       0
## 372                    1.731  21       0
## 427                    0.256  25       0
## 495                    0.174  22       0
## 523                    0.189  26       0
## 685                    0.640  69       0
## 707                    0.261  30       1

BMI değerleri 0 yazan gözlemler tespit edilmiştir.

DiabetesPedigreeFunction Değişkeni

zeroDiabetesPedigreeFunction <- diabetes$DiabetesPedigreeFunction == 0

diabetes[zeroDiabetesPedigreeFunction, ]
## [1] Pregnancies              Glucose                  BloodPressure           
## [4] SkinThickness            Insulin                  BMI                     
## [7] DiabetesPedigreeFunction Age                      Outcome                 
## <0 rows> (or 0-length row.names)

DiabetesPedigreeFunction değerleri 0 yazan gözlemler tespit edilmemiştir.

Age Değişkeni

zeroAge <- diabetes$Age == 0

diabetes[zeroAge, ]
## [1] Pregnancies              Glucose                  BloodPressure           
## [4] SkinThickness            Insulin                  BMI                     
## [7] DiabetesPedigreeFunction Age                      Outcome                 
## <0 rows> (or 0-length row.names)

Age değerleri 0 yazan gözlemler tespit edilmemiştir.

3.2 Eksik Değer Doldurma

BloodPressure, SkinThickness, BMI değişkenlerinde “0” değerleri tespit edilmiştir. İlgili değişkenler, 0 sayısını normal şartlar altında içermeyeceğinden ötürü, eksik değer doldurma işlemi yapılacaktır.

BloodPressure Değişkeni

BloodPressure değişkeni nicel değişken olduğu için Regresyon Yöntemi ile eksik değerler doldurulacaktır.

Öncelikle 0 yazan BloodPressure değerleri “NA” olarak değiştirilmeli;

diabetes$BloodPressure[diabetes$BloodPressure == 0] <- NA

Eksik değerlerin doldurulması:

library(Hmisc)
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
impute_arg <- aregImpute(BloodPressure ~ Pregnancies + Glucose + BMI + SkinThickness + Insulin + DiabetesPedigreeFunction + Age + Outcome,
                         data = diabetes, n.impute = 1)
## Iteration 1 
imputed_BloodPressure <- impute_arg$imputed$BloodPressure 

rows_with_missing_BloodPressure <- which(is.na(diabetes$BloodPressure))

diabetes$BloodPressure[rows_with_missing_BloodPressure] <- imputed_BloodPressure

SkinThickness Değişkeni

SkinThickness değişkeni nicel değişken olduğu için Regresyon Yöntemi ile eksik değerler doldurulacaktır.

Öncelikle 0 yazan SkinThickness değerleri “NA” olarak değiştirilmeli;

diabetes$SkinThickness[diabetes$SkinThickness == 0] <- NA

Eksik değerlerin doldurulması:

library(Hmisc)
impute_arg <- aregImpute(SkinThickness ~ Pregnancies + Glucose + BMI + BloodPressure + Insulin + DiabetesPedigreeFunction + Age + Outcome,
                         data = diabetes, n.impute = 1)
## Iteration 1 
imputed_SkinThickness <- impute_arg$imputed$SkinThickness 

rows_with_missing_SkinThickness <- which(is.na(diabetes$SkinThickness))

diabetes$SkinThickness[rows_with_missing_SkinThickness] <- imputed_SkinThickness

BMI Değişkeni

BMI değişkeni nicel değişken olduğu için Regresyon Yöntemi ile eksik değerler doldurulacaktır.

Öncelikle 0 yazan BMI değerleri “NA” olarak değiştirilmeli;

diabetes$BMI[diabetes$BMI == 0] <- NA

Eksik değerlerin doldurulması:

library(Hmisc)
impute_arg <- aregImpute(BMI ~ Pregnancies + Glucose + BloodPressure + SkinThickness + Insulin + DiabetesPedigreeFunction + Age + Outcome,
                         data = diabetes, n.impute = 1)
## Iteration 1 
imputed_BMI <- impute_arg$imputed$BMI 

rows_with_missing_BMI <- which(is.na(diabetes$BMI))

diabetes$BMI[rows_with_missing_BMI] <- imputed_BMI

3 değişkenin eksik değerleri, Regresyon Yöntemi ile dolduruldu. Kontrol edelim;

BloodPressure Değişkeni

zeroBloodPressure <- diabetes$BloodPressure == 0

diabetes[zeroBloodPressure, ]
## [1] Pregnancies              Glucose                  BloodPressure           
## [4] SkinThickness            Insulin                  BMI                     
## [7] DiabetesPedigreeFunction Age                      Outcome                 
## <0 rows> (or 0-length row.names)

SkinThickness Değişkeni

zeroSkinThickness <- diabetes$SkinThickness == 0

diabetes[zeroSkinThickness, ]
## [1] Pregnancies              Glucose                  BloodPressure           
## [4] SkinThickness            Insulin                  BMI                     
## [7] DiabetesPedigreeFunction Age                      Outcome                 
## <0 rows> (or 0-length row.names)

BMI Değişkeni

zeroBMI <- diabetes$BMI == 0

diabetes[zeroBMI, ]
## [1] Pregnancies              Glucose                  BloodPressure           
## [4] SkinThickness            Insulin                  BMI                     
## [7] DiabetesPedigreeFunction Age                      Outcome                 
## <0 rows> (or 0-length row.names)

Eksik değer doldurma işlemi tamamlandı.

4 Uygulama

4.1 Bağımlı Değişken Ağırlık Kontrolü

Outcome değişkeni bağımlı değişkendir. Ancak bağımlı değişkenin frekanslarına ve oranlarına bakıldığında uzaklık tespit edilmektedir. Diyabeti olmayanların oranı %35 iken diyabeti olanların oranı %65’dir.

frekans_tablosu <- table(diabetes$Outcome)

oranlar <- prop.table(frekans_tablosu)

sonuc <- data.frame(Kategori = names(frekans_tablosu), Frekanslar = as.numeric(frekans_tablosu), Oranlar = as.numeric(oranlar))
sonuc
##   Kategori Frekanslar   Oranlar
## 1        0        500 0.6510417
## 2        1        268 0.3489583

Değişkenin ağırlığını birbirine yaklaştırmak için örneklem seçelim.

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
## 
##     src, summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# Outcome değeri 1 olanların sayısı
n_outcome_1 <- sum(diabetes$Outcome == 1)

# Yeni Outcome değeri 1 olanların sayısı (268 olacak)
n_new_outcome_1 <- 268

# Yeni Outcome değeri 0 olanların sayısı (402 olacak)
n_new_outcome_0 <- 402

# Rasgele örneklemleri oluşturun
set.seed(123)
diabetes <- diabetes %>%
  filter(Outcome == 1) %>%
  slice_sample(n = n_new_outcome_1) %>%
  bind_rows(diabetes %>%
              filter(Outcome == 0) %>%
              slice_sample(n = n_new_outcome_0))

Veri setinin yeni gözlem sayısı:

nrow(diabetes)
## [1] 670

Frekans ve oranlar yeniden incelenirse;

frekans_tablosu <- table(diabetes$Outcome)

oranlar <- prop.table(frekans_tablosu)

sonuc <- data.frame(Kategori = names(frekans_tablosu), Frekanslar = as.numeric(frekans_tablosu), Oranlar = as.numeric(oranlar))
sonuc
##   Kategori Frekanslar Oranlar
## 1        0        402     0.6
## 2        1        268     0.4

Bağımlı değişken çıktı sonuçları birbirine yaklaştı. Oranlar ise Diyabeti olmayanlar için %60 ve Diyabeti olanlar için %40 şeklinde belirlendi.

4.2 Kategorik Değişkenleri Belirleme

Veri setinde yer alan Insulin, BMI ve Outcome değişkenlerini kategorik değişkenlere çevirelim.

Insulin Değişkeni:

“Öğün başlangıcından 2 saat sonra kan şekerinin ölçülmesi sonucunda kan glukoz seviyesinin 200 mg/Dl’nin üzerinde olması diyabet hastalığının, 140-199 mg/Dl aralığında olması gizli şeker adı verilen pre-diyabet döneminin göstergesidir.” [1]

Bu anlamda, Insulin değeri 140’dan az olanlara düşük, 140-199 olanlara gizli şeker, 199’dan fazla olanlara şeker yazalım.

diabetes$Insulin <- ifelse(diabetes$Insulin < 140, "Normal", 
                            ifelse(diabetes$Insulin >= 140 & diabetes$Insulin <= 199, "Gizli Şeker", "Diyabet"))

BMI Değişkeni

“18, 5 kg/m² ’nin altındaki sonuçlar: İdeal kilonun altında 18, 5 kg/m² ile 24, 9 kg/m² arasındaki sonuçlar: İdeal kiloda 25 kg/m² ile 29, 9 kg/m² arasındaki sonuçlar: İdeal kilonun üstünde 30 kg/m² ile 39, 9 kg/m² arasındaki sonuçlar: İdeal kilonun çok üstünde (obez) 40 kg/m² üzerindeki sonuçlar: İdeal kilonun çok üstünde (morbid obez)” [2]

BMI değerleri incelendiğinde, 18.5 altında kalan gözlemlerin, diğer kategorilerdeki gözlemlere göre oldukça az olduğu gözlenmiştir. Bu sebeple öncelikle BMI değeri 18.5’den düşük olan gözlemler incelenecektir.

low_bmi_diabetes <- diabetes[diabetes$BMI <= 18.5, ]

low_bmi_diabetes
##     Pregnancies Glucose BloodPressure SkinThickness Insulin  BMI
## 533           1      97            70            15  Normal 18.2
##     DiabetesPedigreeFunction Age Outcome
## 533                    0.147  21       0

Kontrol edildiği üzere yalnızca 1 gözlemin BMI sonucu 18.5’in altında yer almıştır. Bu durum, kategori oluşturma aşamasında çalışmayı iyi devam ettiremeyeceğinden ötürü bir üst kategori olan “İdeal” kategorisine dahil edilecektir.

İdeal kategorsinin sınırları 18.5 - 24.9 olarak belirlenmişti. Alt sınıra olan yakınlığı sebebi ile gözlem silinmektense bu yöntemi uygulamak tercih edilmiştir.

BMI değişkenini kategorik değişkene çevirmek için;

diabetes$BMI <- ifelse(diabetes$BMI <= 24.9, "İdeal",
                              ifelse(diabetes$BMI >= 25 & diabetes$BMI <= 29.9, "Kilolu",
                                     ifelse(diabetes$BMI >= 30 & diabetes$BMI <= 39.9, "Obez",
                                            "Morbid Obez")))
table(diabetes$BMI)
## 
##       İdeal      Kilolu Morbid Obez        Obez 
##          87         152          88         343

Outcome Değişkeni

Kategorize etmek için;

0: Diyabeti yok, 1: Diyabeti var

diabetes$Outcome <- ifelse(diabetes$Outcome == 0, "Diyabeti Yok", "Diyabeti Var")

5 Uygulama

5.1 Nitel Değişkenlerin Frekans Analizi

  • İnsülin değişkeni
frekans_tablosu <- table(diabetes$Insulin)

oranlar <- prop.table(frekans_tablosu)

sonuc <- data.frame(Kategori = names(frekans_tablosu), Frekanslar = as.numeric(frekans_tablosu), Oranlar = as.numeric(oranlar))
sonuc
##      Kategori Frekanslar   Oranlar
## 1     Diyabet         80 0.1194030
## 2 Gizli Şeker         76 0.1134328
## 3      Normal        514 0.7671642
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.1
## Zorunlu paket yükleniyor: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.1
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:Hmisc':
## 
##     subplot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
cross <- as.data.frame(prop.table(table(diabetes$Insulin))) 
colnames(cross)[1] <- "Insulin"
plot_ly(cross, labels = ~Insulin, values = ~Freq, type = 'pie')%>% layout(title ='Diyabet Durumu')
  • BMI değişkeni
frekans_tablosu <- table(diabetes$BMI)

oranlar <- prop.table(frekans_tablosu)

sonuc <- data.frame(Kategori = names(frekans_tablosu), Frekanslar = as.numeric(frekans_tablosu), Oranlar = as.numeric(oranlar))
sonuc
##      Kategori Frekanslar   Oranlar
## 1       İdeal         87 0.1298507
## 2      Kilolu        152 0.2268657
## 3 Morbid Obez         88 0.1313433
## 4        Obez        343 0.5119403
library(plotly)

cross <- as.data.frame(prop.table(table(diabetes$BMI))) 
colnames(cross)[1] <- "BMI"
plot_ly(cross, labels = ~BMI, values = ~Freq, type = 'pie')%>% layout(title ='BMI Durumu')
  • Outcome Değişkeni
frekans_tablosu <- table(diabetes$Outcome)

oranlar <- prop.table(frekans_tablosu)

sonuc <- data.frame(Kategori = names(frekans_tablosu), Frekanslar = as.numeric(frekans_tablosu), Oranlar = as.numeric(oranlar))
sonuc
##       Kategori Frekanslar Oranlar
## 1 Diyabeti Var        268     0.4
## 2 Diyabeti Yok        402     0.6
library(plotly)

cross <- as.data.frame(prop.table(table(diabetes$Outcome))) 
colnames(cross)[1] <- "Outcome"
plot_ly(cross, labels = ~Outcome, values = ~Freq, type = 'pie')%>% layout(title ='Çıktı')

6 Dönüşümlere Karar Verme

Glucose Değişkeni

Histogramı incelenerek Logaritmik dönüşüm uygulamasına karar verilmiştir.

DiabetesPedigreeFunction Değişkeni

Histogramı incelenerek Logaritmik dönüşüm uygulamasına karar verilmiştir.

Age Değişkeni

Histogramı incelenerek Logaritmik dönüşüm uygulamasına karar verilmiştir.

7 Dönüşüm

Glucose değişkeni için logaritmik dönüşüm, DiabetesPedigreeFunction değişkeni için logaritmik dönüşüm, Age değişkeni için logaritmik dönüşüm uygulanacaktır.

diabetes$glucose_log <- log10(diabetes$Glucose)
diabetes$diabetesPedigreeFunction_log <- log10(diabetes$DiabetesPedigreeFunction)
diabetes$age_log <- log10(diabetes$Age)

Çıktılar SPSS’de incelenmiştir.

8 Grafikler

8.1 Sürekli Değişkenlerin Histogram Grafikleri

Glucose Değişkeni

library(ggplot2)
ggplot(diabetes, aes(glucose_log)) +
  geom_histogram(aes(y=..density..), fill="seashell2", color="black", bins=30) +
  geom_density(alpha=.4, fill="cadetblue3") +
  theme_minimal() +
  labs(title = "Glucose Degerleri")+
  theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 20))
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 3 rows containing non-finite values (`stat_bin()`).
## Warning: Removed 3 rows containing non-finite values (`stat_density()`).

BloodPressure

ggplot(diabetes, aes(BloodPressure)) +
  geom_histogram(aes(y=..density..), fill="seashell2", color="black", bins=30) +
  geom_density(alpha=.4, fill="cadetblue3") +
  theme_minimal() +
  labs(title = "BloodPressure Degerleri")+
  theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 20))

SkinThickness

ggplot(diabetes, aes(SkinThickness)) +
  geom_histogram(aes(y=..density..), fill="seashell2", color="black", bins=30) +
  geom_density(alpha=.4, fill="cadetblue3") +
  theme_minimal() +
  labs(title = "SkinThickness Degerleri")+
  theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 20))

DiabetesPedigreeFunction

ggplot(diabetes, aes(diabetesPedigreeFunction_log)) +
  geom_histogram(aes(y=..density..), fill="seashell2", color="black", bins=30) +
  geom_density(alpha=.4, fill="cadetblue3") +
  theme_minimal() +
  labs(title = "DiabetesPedigreeFunction Degerleri")+
  theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 20))

Age

ggplot(diabetes, aes(Age)) +
  geom_histogram(aes(y=..density..), fill="seashell2", color="black", bins=30) +
  geom_density(alpha=.4, fill="cadetblue3") +
  theme_minimal() +
  labs(title = "Age Degerleri")+
  theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 20))

hist(diabetes$Age)

8.2 Sürekli Değişkenlerin Kutu Grafikleri

Glucose Değişkeni

boxplot(diabetes$glucose_log, col = "orange")
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 1 is not drawn
title(main = "Glucose Kutu Grafigi", font.main = 2, cex.main = 2)

BloodPressure Değişkeni

boxplot(diabetes$BloodPressure, main = "BloodPressure Kutu Grafiği", col="orange")

SkinThickness Değişkeni

boxplot(diabetes$SkinThickness, main = "SkinThickness Kutu Grafiği", col="orange")

DiabetesPedigreeFunction Değişkeni

boxplot(diabetes$diabetesPedigreeFunction_log, main = "DiabetesPedigreeFunction Kutu Grafiği", col="orange")

Age Değişkeni

boxplot(diabetes$Age, main = "Age Kutu Grafiği", col="orange")

8.3 Sürekli Değişkenlerin Q-Q Grafikleri

Glucose Değişkeni

qqnorm(diabetes$glucose_log, col = "darkblue", main = "Glucose QQ Plot", ylim = c(-3, 3))
qqline(diabetes$glucose_log, col = "red")

BloodPressure Değişkeni

qqnorm(diabetes$BloodPressure, col = "darkblue", main = "BloodPressure QQ Plot")
qqline(diabetes$BloodPressure, col = "red")

SkinThickness Değişkeni

qqnorm(diabetes$SkinThickness, col = "darkblue", main = "SkinThickness QQ Plot")
qqline(diabetes$SkinThickness, col = "red")

DiabetesPedigreeFunction Değişkeni

qqnorm(diabetes$diabetesPedigreeFunction_log, col = "darkblue", main = "DiabetesPedigreeFunction QQ Plot")
qqline(diabetes$diabetesPedigreeFunction_log, col = "red")

Age Değişkeni

qqnorm(diabetes$age_log, col = "darkblue", main = "Age QQ Plot")
qqline(diabetes$age_log, col = "red")

8.4 Sürekli Değişkenlerin Korelasyonları

diabetes$Outcome <- ifelse(diabetes$Outcome == "Diyabeti Var", 1, 0)
library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.3.1
## Zorunlu paket yükleniyor: xts
## Warning: package 'xts' was built under R version 4.3.1
## Zorunlu paket yükleniyor: zoo
## Warning: package 'zoo' was built under R version 4.3.1
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend

Glucose, BloodPressure, SkinThickness, DiabetesPedigreeFunction ve Age Değişkenleri

Glucose değişkenine dönüşüm uygulanıp normallik sağlanmıştı. Ancak glucose_log değişkeninde -Inf değerler söz konusu olduğu için Glucose değerlerine +1 eklenerek logaritması alınana yeni bir değişken oluşturuldu. Bu sayede -Inf olan değerler problem çıkartmayacaktır.

diabetes$Glucose_plus <- log10(diabetes$Glucose + 1)  

cor_diabetes <- diabetes[, c(3, 4, 11, 12, 13)]

chart.Correlation(cor_diabetes, histogram = TRUE, pch = 19, method="pearson")
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter